<?php
namespace WebApper\Shortcode;

/*
 * [calendar id='Calendar']
 *
 */
class Calendar extends \WebApper\Shortcode {
	
    /**
     * Define shortcode properties
     *
     */
	protected $shortcode = 'calendar';

    /**
     * Handles the add post shortcode
     *
     * @param array $atts
     */
    public function shortcode( $atts ) {
		?>
        <div id="calendar"></div>
        <script type="text/javascript">
			jQuery(document).ready(function($) {
				var eventsInline = [ 
					<?php
						global $webapper, $wpdb, $current_user;
						get_currentuserinfo();
						$tasks = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$webapper->tables->tasks} WHERE user_id = %d", $current_user->ID ) );
						$separator = "";
						foreach ( $tasks as $task ) :
							echo $separator;
							echo '{ "date": "' . ($task->due*1000) . '", "type": "meeting", "title": "' . $task->subject . '", "description": "' . $task->description . '", "url": "' . site_url('taskbox') . '" }';
							$separator = ",";
						endforeach;
					?>
				];
				$('div#calendar').eventCalendar({
					jsonData: eventsInline
				});
			});
		</script>
        <?php
	}

}

$initialize = new Calendar(); 

?>